package cn.witsky.rtp2ws.push.disruptor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.lmax.disruptor.WorkHandler;
import cn.witsky.rtp2ws.cache.CallManager;
import cn.witsky.rtp2ws.domain.CallInfo;
import cn.witsky.rtp2ws.domain.Message;

public class EventConsumer implements WorkHandler<Message> {
	private static Logger logger = LoggerFactory.getLogger(EventConsumer.class);

	@Override
	public void onEvent(Message message) throws Exception {
		String callId = message.getCallId();
		CallInfo call = CallManager.getCall(callId);
		if (call == null) {
			logger.error("呼叫callId:{}的会话不存在！message.seq:{}", callId, message.getSeq());
			return;
		}
		if(message.getCurrentTimeMillis()>0) {
			Message newMessage=(Message) message.clone();
			call.getRtp(message.isCaller()).sendMsg(newMessage);
		}
	}
}